package com.dongdongshop.controller;


import com.dongdongshop.data.Result;
import com.dongdongshop.model.TbTypeTemplate;
import com.dongdongshop.service.TypeService;
import com.dongdongshop.vo.TypeTemplateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("type")
public class TypeController {

    @Autowired
    private TypeService typeService;

    @PostMapping
    public Result TypeList(@RequestBody TypeTemplateVo type){
        try {
            List<TypeTemplateVo> typeTemplateVo= typeService.typeList(type);
            return Result.OK().setData(typeTemplateVo);
        }catch (Exception e){
            return Result.er();
        }
    }

    @PostMapping("addType")
    public Result addType(TbTypeTemplate tbTypeTemplate){
        try {
            typeService.addType(tbTypeTemplate);
            return Result.OK();
        }catch (Exception e){
            return Result.er();
        }
    }

    //删除
    @PostMapping("deletes")
    public Result deletes(Long[] ids){
        try {
            typeService.deletes(ids);
            return Result.OK();
        }catch (Exception e){
            return Result.er();
        }
    }

    //通过id查询数据
    @PostMapping("toupdate")
    public Result toupdate(Long id){
        try {
            TypeTemplateVo vo =  typeService.toupdate(id);
            return Result.OK().setData(vo);
        }catch (Exception e){
            return Result.er();
        }
    }

}
